extern float4x4 gWorld;
extern float4x4 gWVP;
extern float4x4 gWIT;

extern float4 gDiffuse;
extern float4 gSpecular;

extern texture gDiffuseTex;
extern texture gSpecularTex;
extern texture gNormalTex;

sampler DiffuseS = sampler_state
{
	Texture = <gDiffuseTex>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
};

sampler SpecularS = sampler_state
{
	Texture = <gSpecularTex>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
};

struct OutputVS
{
	float4 Position : POSITION0;
	float2 TexCoord : TEXCOORD0;
	float3 Normal : TEXCOORD1;
};

OutputVS TransformVS(float3 posI : POSITION0, float3 normalI : NORMAL0, float2 TexCoordI : TEXCOORD0)
{
	OutputVS outVS = (OutputVS)0;
	
	outVS.Normal = mul(float4(normalI, 0.0f), gWIT).xyz;
	outVS.Normal = normalize(outVS.Normal); // As this is normalized per pixel once interpolated, is this necessary?
	
	outVS.Position = mul(float4(posI, 1.0f), gWVP);
	outVS.TexCoord = TexCoordI;
	
	return outVS;
}

float4 AmbientPS(OutputVS In) : COLOR
{
    float3 Col = tex2D(DiffuseS, In.TexCoord).rgb;

	Col += 3.0f * Col * dot(In.Normal, normalize(float3(-1.0f, 1.0f, -1.0f)));

	Col *= 0.25f;

	//Col = (float3(1.0f, 1.0f, 1.0f) + In.Normal) * 0.5f;

	return float4(Col.rgb, gDiffuse.a);
}

technique DiffuseTech {
	pass P0 {
        SRCBLEND = SrcAlpha;
        DESTBLEND = InvSrcAlpha;
        ALPHABLENDENABLE = true;
		vertexShader = compile vs_2_0 TransformVS();
		pixelShader  = compile ps_2_0 AmbientPS();
	}
}